/**
 * @file	  双路pwm
 * @brief	  同时采集两路pwm，且可测占空比
 * @note	  基于正点原子Mini开发版，仅供学习参考,得到频率与占空比得自己再加几步算法
 * @author	  YYJ
 * @email	  2779314051@qq.com
 * @data	  2020/12/20
 */
#include "stm32f10x.h"
#include "delay.h"
#include "usart.h"
#include "tim_get.h"

int main(void)
{	
	int time_val_H=0,time_val_L=0;
	delay_init();
	uart_init(115200);
	TIM4_Capture_Init(0xfffe,0);
	while(1)
	{
		if (TIM4_flag_L1&0x8000)
		{
			time_val_H = TIM4_capture_H1 + (TIM4_flag_H1&0x7fff)*65535;//高电平时钟数
			time_val_L = TIM4_capture_L1 + (TIM4_flag_L1&0x3fff)*65535;//低电平时钟数
			TIM4_flag_H1=0;
			TIM4_flag_L1=0;
			printf("1.%d,%d\r\n",time_val_H, time_val_L);
		}
		if (TIM4_flag_L2&0x8000)
		{
			time_val_H = TIM4_capture_H2 + (TIM4_flag_H2&0x7fff)*65535;//高电平时钟数
			time_val_L = TIM4_capture_L2 + (TIM4_flag_L2&0x3fff)*65535;//低电平时钟数
			TIM4_flag_H2=0;
			TIM4_flag_L2=0;
			printf("2.%d,%d\r\n",time_val_H, time_val_L);
		}
		delay_ms(500);
		//printf("%d\r\n", count);
	}
}